apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubeadm.kubernetes.io/etcd.advertise-client-urls: https://{{ current_host_ip }}:2379
  creationTimestamp: null
  labels:
    component: etcd
    tier: control-plane
  name: etcd
  namespace: kube-system
spec:
  containers:
  - command:
    - etcd
    - --name=etcd-{{ inventory_hostname }}
    - --advertise-client-urls=https://{{ current_host_ip }}:2379
    - --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
    - --cert-file=/etc/kubernetes/pki/etcd/server.crt
    - --cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
    - --key-file=/etc/kubernetes/pki/etcd/server.key
    - --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt
    - --peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt
    - --peer-key-file=/etc/kubernetes/pki/etcd/peer.key
    - --peer-client-cert-auth=true
    - --listen-peer-urls=https://{{ current_host_ip }}:2380
    - --listen-metrics-urls=http://127.0.0.1:2381
    - --listen-client-urls=https://127.0.0.1:2379,https://{{ current_host_ip }}:2379
    - --initial-cluster-state={{ etcd_cluster_state }}
    - --initial-advertise-peer-urls=https://{{ current_host_ip }}:2380
    - --initial-cluster={{ etcd_initial_cluster }}
    - --initial-cluster-token=etcd-cluster-token
    - --client-cert-auth=true
    - --snapshot-count=10000
    - --data-dir=/var/lib/etcd
    # 推荐一小时压缩一次数据这样可以极大的保证集群稳定
    - --auto-compaction-retention=1
    # Etcd Raft消息最大字节数，官方推荐是10M
    - --max-request-bytes=10485760
    # ETCD db数据大小，默认是2G，官方推荐是8G
    - --quota-backend-bytes=8589934592
    image: {{ etcd_image }}
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 127.0.0.1
        path: /health
        port: 2381
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
{% if kube_version is version('1.18', '>=') %}
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 127.0.0.1
        path: /health
        port: 2381
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
{% endif %}
    name: etcd
    resources: {}
    volumeMounts:
    - mountPath: /var/lib/etcd
      name: etcd-data
    - mountPath: /etc/kubernetes/pki/etcd
      name: etcd-certs
    - mountPath: /etc/localtime
      name: localtime
      readOnly: true
  hostNetwork: true
  priorityClassName: system-cluster-critical
  volumes:
  - hostPath:
      path: {{ etcd_data_dir }}
      type: DirectoryOrCreate
    name: etcd-data
  - hostPath:
      path: /etc/kubernetes/pki/etcd
      type: DirectoryOrCreate
    name: etcd-certs
  - hostPath:
      path: /etc/localtime
      type: File
    name: localtime
status: {}